<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"	
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:cc="http://java.sun.com/jsf/composite">

<cc:interface componentType="org.jboss.seam.faces.InputContainer">
	<cc:actionSource name="parameters" targets="linkList#{cc.attrs.id} linkEdit#{cc.attrs.id}" />
	<cc:attribute name="columns" required="true" shortDescription="Colunas que serão exibidas no modal." />
	<cc:attribute name="editable" required="false" default="false" />
	<cc:attribute name="id" required="true" />
	<cc:attribute name="width" required="false" default="1024px"/>
	<cc:attribute name="modalAction" required="true" />
	<cc:attribute name="legend" required="true" />
	<cc:attribute name="list" required="true" />
	<cc:attribute name="readOnly" required="false" shortDescription="Define a lista somente para exibir informações." />
	<cc:attribute name="onRemove" required="false" method-signature="void action()" />
	<cc:attribute name="update" required="false" />
	<cc:attribute name="selection" required="true" />
	<cc:attribute name="disableInclude" required="false" default="false" />
</cc:interface>

<cc:implementation xmlns:sig="http://java.sun.com/jsf/composite/components">
	<p:fieldset id="fieldset#{cc.attrs.id}" legend="#{cc.attrs.legend}" style="width: #{cc.attrs.width}">
	
		<p:commandLink
			id="linkList#{cc.attrs.id}"
			action="#{cc.attrs.list.startModal()}"
			oncomplete="PF('dialogModal#{cc.attrs.id}').show();"
			partialSubmit="true"
			process="@this"			        
			update=":#{cc.attrs.id}:formModal#{cc.attrs.id}:panelListModal#{cc.attrs.id}"
			value="+ #{messages['link.include']}" styleClass="linkIncluirSecundario"
			rendered="#{cc.attrs.list != null}"
			disabled="#{cc.attrs.disableInclude}"	
		/>
			
		<p:commandLink
			id="linkEdit#{cc.attrs.id}"
			action="#{cc.attrs.modalAction.startModal()}"
			oncomplete="PF('dialogModal#{cc.attrs.id}').show();"
			partialSubmit="true"
			process="@this"
			update=":#{cc.attrs.id}:formModal#{cc.attrs.id}:panelEditModal#{cc.attrs.id}"
			value="+ #{messages['link.include']}" styleClass="linkIncluirSecundario"
			rendered="#{cc.attrs.modalAction != null and cc.attrs.list == null}"
			disabled="#{cc.attrs.disableInclude}">
			<p:resetInput target=":#{cc.attrs.id}:formModal#{cc.attrs.id}:panelFields#{cc.attrs.id}" />	
		</p:commandLink>
			
		<p:dataTable
			id="dataTable#{cc.attrs.id}" value="#{cc.attrs.selection}" var="entity" emptyMessage="" rowKey="#{entity.id}" editable="#{cc.attrs.editable}" editMode="cell">
	        
	        <p:ajax event="rowSelect" update="dataTable#{cc.attrs.id}" immediate="true" partialSubmit="true" />
	        <p:ajax event="rowUnselect" update="dataTable#{cc.attrs.id}" immediate="true" partialSubmit="true" />
	        <p:ajax event="cellEdit" listener="#{cc.attrs.list.onCellEdit}" process="@this" update="dataTable#{cc.attrs.id}" />
	        				        
			<ui:include src="#{cc.attrs.columns}" />
		    
		    <p:column width="5%" styleClass="columnCenter" rendered="#{cc.attrs.readOnly == null}">
		    	<p:commandLink partialSubmit="true" process="@this" update=":#{cc.attrs.id}:formModal#{cc.attrs.id}:panelEditModal#{cc.attrs.id}"
		    		rendered="#{cc.attrs.modalAction != null}"
		    		oncomplete="PF('dialogModal#{cc.attrs.id}').show();">
		        	<h:graphicImage library="images" name="editar.png" alt="Editar" title="Editar" />
		        	<f:setPropertyActionListener target="#{cc.attrs.modalAction.instance}" value="#{entity}" />
		        	<!-- Parametro utilizado para
		        	 	o modal ao abrir diferenciar entre uma edicao e um inclusao. E utilizado no dialog.xhtml -->		        	
		        	<f:setPropertyActionListener target="#{cc.attrs.modalAction.editModal}" value="#{true}" />
		        </p:commandLink>		        
		        <p:spacer width="10" rendered="#{cc.attrs.modalAction != null}" />
		    	<p:commandLink partialSubmit="true" process="@this"
		    		update=":formCrud:#{cc.attrs.id}:dataTable#{cc.attrs.id}"
		    		actionListener="#{cc.attrs.selection.remove(entity)}"
		    		rendered="#{cc.attrs.onRemove == null}">
		        	<h:graphicImage library="images" name="deletar.png" alt="Excluir" title="Excluir" />
		        </p:commandLink>		        
		    	<p:commandLink partialSubmit="true" process="@this"
		    		update=":formCrud:#{cc.attrs.id}:dataTable#{cc.attrs.id} #{cc.attrs.update}"		    	
		    		action="#{cc.attrs.onRemove}"
		    		actionListener="#{cc.attrs.selection.remove(entity)}"
		    		rendered="#{cc.attrs.onRemove != null}">
		        	<h:graphicImage library="images" name="deletar.png" alt="Excluir" title="Excluir" />
		        </p:commandLink>
		    </p:column>
			
		</p:dataTable>
				
	</p:fieldset>
	 
</cc:implementation>
</html>